/**
 * File name:      MessageSourceAdapter.java
 * Date:           2013-4-2
 * Description:    // 用于详细说明此程序文件完成的主要功
 *                 // 能与其他模块或函数的接口，输出值、
 *                 // 取值范围、含义及参数间的关系
 * Modify History:     Date             Programmer       Notes
 *                    ---------        ---------------  ---------
 *                    2013-4-2            胡少磊                           Initial
 **********************************************************************/
package com.wy.framework.adapter;

import java.io.File;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created on 2013-4-2
 * <p>
 * Title: [公共模块]
 * </p>
 * <p>
 * Description: 消息处理
 * </p>
 * 
 * @version 1.0
 */
public class RsyncAdapter {

	// 日志操作符声明
	private static Logger logger = LoggerFactory.getLogger(RsyncAdapter.class);

	/**
	 * 同步文件夹
	 */
	public int rsyncFolder(String cmdPath) {
		String[] cmd = new String[3];
		cmd[0] = "sh";
		cmd[1] = "-c";
		File shFile = new File(cmdPath);
		if (!shFile.exists() || !shFile.isFile()) {
			return 999998;
		}
		cmd[2] = cmdPath;

		Runtime rt = null;
		Process proc = null;
		int exitVal = 999999;

		try {
			rt = Runtime.getRuntime();
			proc = rt.exec(cmd);
			exitVal = proc.waitFor();

			return exitVal;
		} catch (IOException ioe) {
			logger.error(ioe.getMessage());
			return 999997;
		} catch (InterruptedException ie) {
			logger.error(ie.getMessage());
			return 999996;
		}
	}
}
